package com.atguigu.serviceedu.controller.front;

import com.atguigu.commonutils.R;
import com.atguigu.serviceedu.client.OrdersClient;
import com.atguigu.serviceedu.entity.History;
import com.atguigu.serviceedu.entity.Like;
import com.atguigu.serviceedu.entity.Order;
import com.atguigu.serviceedu.entity.UcenterMember;
import com.atguigu.serviceedu.service.EduCourseService;
import com.atguigu.serviceedu.service.UcenterMemberService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @Author: GengKY
 * @Date: 2022/4/15 9:09
 */
@Api(description = "会员个人信息")
//@CrossOrigin
@RestController
@RequestMapping("/eduService/userinfo")
public class UserInfoController {

    @Autowired
    private EduCourseService eduCourseService;

    @Autowired
    private UcenterMemberService ucenterMemberService;

    @Autowired
    private OrdersClient ordersClient;


    @ApiOperation(value = "根据会员ID查询信息")
    @GetMapping("getFrontUserInfo/{userid}")
    public R getUserInfoFront(@PathVariable String userid){
        //1.根据 会员ID 查询会员的基本信息
        UcenterMember numberinfo = ucenterMemberService.getById(userid);

        List<History> historyList = ordersClient.getHistoryListByNumberId(userid);
        List<Like> likeList = ordersClient.getLikeListByNumberId(userid);
        List<Order> orderList = ordersClient.getOrderListByNumberId(userid);

        System.out.println(numberinfo.toString());
        System.out.println(historyList.size());
        System.out.println(likeList.size());
        System.out.println(orderList.size());

        return R.ok().data("memberInfo",numberinfo)
                .data("historyList",historyList)
                .data("likeList",likeList)
                .data("orderList",orderList);
    }




    @ApiOperation(value = "根据会员ID更新信息")
    @GetMapping("updateNumberById/{id}")
    public R updateMumberByID(@RequestBody UcenterMember ucenterMember){
        boolean flag = ucenterMemberService.updateById(ucenterMember);
        if (flag){
            return R.ok();
        }else {
            return R.error();
        }
    }


}
